/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.ac.cput.ismaila.designPatterns.behavioural.observer;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author Chelsea
 */
public class WeatherStation implements WeatherSubject {
Set<WeatherObserver>weatherObservers;
int temperature;
public WeatherStation(int temperature){
weatherObservers=new HashSet<WeatherObserver>();
this.temperature=temperature;
}	
@Override
public void addObserver(WeatherObserver weatherObserver){
weatherObservers.add(weatherObserver);
}
@Override
public void removeObserver(WeatherObserver weatherObserver){
weatherObservers.remove(weatherObserver);
}
@Override
public String doNotify(){
String notification = "";
Iterator<WeatherObserver> it = weatherObservers.iterator();
while(it.hasNext()){
WeatherObserver weatherObserver=it.next();
 notification = notification + weatherObserver.doUpdate(temperature);
}
return notification;
}
public String setTemperature(int newTemperature){
String notification;
temperature = newTemperature;
notification = doNotify();
return "nnWeatherstationsettingtemperatureto"+newTemperature+notification;
}

}
